
console.log("main_url:" + MAIN_URL);
{
	var newscript = document.createElement('script');
	newscript.setAttribute('type','text/javascript');
//	newscript.setAttribute('src','../scripts/std_sys.js');
	var head = document.getElementsByTagName('head')[0];
	head.appendChild(newscript);
	newscript.onload=function(){
		start();
	}
}
if (!window.localStorage) {
	console.log('浏览器版本太低，不支持localStorage');
}
submit.onclick = function(){
	var id = document.getElementById('id');
	var pwd = document.getElementById('pwd');
	var sign = document.getElementById('sign_in');
  var xmlDoc = document.implementation.createDocument(null, 'root');
  var element = xmlDoc.createElement('child');
  element.setAttribute('id', id.value);
  element.setAttribute('pwd', pwd.value);
  element.setAttribute('token', storage.token);
  xmlDoc.documentElement.appendChild(element);
  var xmlString = new XMLSerializer().serializeToString(xmlDoc);
  console.log("s" + xmlString);
	storage.id = id.value;
	var xhttp = new XMLHttpRequest();
	xhttp.open("post", MAIN_URL + "/ts/account/sign_in" , false);
  xhttp.setRequestHeader ('content-type', 'text/plain');
	xhttp.send(xmlString);
	console.log("responst " + xhttp.responseText);
  var parser = new DOMParser();
  xmlDoc = parser.parseFromString(xhttp.responseText, "application/xml");
  var root = xmlDoc.documentElement;
  var child = root.childNodes[0];
  var token = child.getAttribute("token");
  var error = child.getAttribute("error");
	storage.token = token;
  console.log("back:" + document.referrer);
	if (error) {
    console.log("error");
		document.getElementById("demo").innerHTML = error;
	} else if (token) {
    console.log("token");
		document.getElementById("demo").innerHTML = token;
    var jump;
    if (storage.previous && (storage.previous != "sign_up.html")) {
      jump = storage.previous;
    } else {
      jump = "chat.html";
    }
   //   window.history.back();
    top.window.location.href=jump + "?token=" + storage.token + "&id=" + storage.id;
    //  top.window.location.href="http://bef.gitee.io";
	} else {
    console.log("no token and no error");
  }
    console.log("no token and no error");
}
